var constant = require('../common/constant');
loginController.$inject = ['$scope', '$location','loginService'];

function loginController($scope, $location,loginService) {
    $scope.login = function () {
        $scope.msgNull = false;
        $scope.pwdError = false;
        $scope.accountError = false;
        var account = $scope.account;
        var pwd = $scope.pwd;
        if(isUndefined(account)||isUndefined(pwd)){
            $scope.msgNull = true;
        }else{
            var account = $scope.account;
            var pwd = $scope.pwd;
            loginService.login(account,pwd,function (resposne) {
                console.log("login-resposne:"+JSON.stringify(resposne));
                if(!resposne.data.result){
                    if(resposne.data.code==constant.AccountNoExit){
                        $scope.accountError = true;
                    }else{
                        $scope.pwdError = true;
                    }
                }else{
                    console.log("login success");
                    $location.path('/m/home');
                }
            })
        }


    }
    $scope.regist=function () {
        $location.path('/regist');
    }

    function isUndefined(obj) {
        if(!obj){
            return true;
        }
        return false;
    }

}

module.exports = loginController;